package com.francis.spring.framework.aop.aspect;

import com.francis.spring.framework.aop.intercept.FrancisMethodInterceptor;
import com.francis.spring.framework.aop.intercept.FrancisMethodInvocation;

import java.lang.reflect.Method;

/**
 * @Author Francis
 * @Date 2020/11/23 0:17
 * @Version 1.0
 * @Description:环绕通知
 */
public class FrancisMethodAroundAdviceInterceptor extends FrancisAbstractAspectAdvice implements FrancisAdvice, FrancisMethodInterceptor  {
    private FrancisJoinPoint joinPoint;

    public FrancisMethodAroundAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private Object around(Method method, Object[] args, Object target) throws Throwable {
        return super.invokeAdviceMethod(this.joinPoint, null, null);
    }


    @Override
    public Object invoke(FrancisMethodInvocation invocation) throws Throwable {
        this.joinPoint = invocation;
        return around(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
    }
}
